const db = wx.cloud.database({
  env: 'cloud1-0go5obgu7b9b4d83'
});
const user = db.collection('user')
const persionalInfo = db.collection('personalInfo');
const systemInfo = db.collection('systemInfo');
Page({

  data: {
    userData: "",
    text: "",
    userSelect: [],
    index: 0,
    content: "",
    title: ""
  },
  onClickLeft() {
    wx.navigateBack({
      delta: 1,
    })
  },
  async onLoad(options) {
    let userRes = await user.get();
    this.setData({
      userData: userRes.data
    });
    let arr = new Array()
    for (var i = 0; i < userRes.data.length; i++) {
      arr.push(userRes.data[i].wxName)
    }
    this.setData({
      userSelect: arr
    })
  },
  system() {
    systemInfo.add({
      data: {
        activeIcon: 'circle',
        inactiveIcon: 'more-o',
        desc: new Date().toLocaleString(),
        text: this.data.text
      }
    })
  },

  change({ detail }) {
    this.setData({
      index: detail.value
    })
  },
  persion(e) {

    persionalInfo.add({
      data: {
        createTime: new Date().toLocaleString(),
        userId: this.data.userData[this.data.index]._openid,
        content: this.data.content,
        title: this.data.title
      },
      success() {
        wx.showToast({
          icon: 'success',
          title: '推送成功',
        })
      }
    })
  },
})